package com.dubbo.consumer;

import com.dubbo.provider.service.OrderInfoService;
import com.dubbo.provider.service.UserService;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;

public class StartApplication {
    public static void main(String[] args) throws IOException {
        ClassPathXmlApplicationContext context = new
                ClassPathXmlApplicationContext("dubbo/dubbo-consumer.xml");
        context.start();
        OrderInfoService service = context.getBean(OrderInfoService.class);
        UserService service2 = context.getBean(UserService.class);
        String cmd;
        while (!"exist".equals(cmd = read())) {
            System.out.println(
                    // 轮询的方式  负载均衡 随机
                    service.getOrderInfoById("111")
            );
        }
    }

    private static String read() throws IOException {
        byte[] b = new byte[1024];
        LineNumberReader lineNumber = new LineNumberReader(
                new InputStreamReader(System.in));
        return lineNumber.readLine();
    }
}
